<script setup>
import { editUserData, getUserData } from '../../api'
import { reactive, ref } from 'vue'
const uploadHeader = {
  Authorization: 'Bearer ' + localStorage.getItem('token')
}

const editForm = reactive({
    avatar: '',
    sex: 0,
    desc: '',
    phone: '',
    email: ''
})
const handleSuccess = (file) => {
    editForm.avatar = file.data.url
}

// const getData = async () => {

// }

const editData = async () => {
    const res = await editUserData(editForm)
    console.log('00000000000', res)
}

</script>

<template>
  <div>
    <h1>个人资料</h1>
    <el-form class="loginForm" :model="editForm" label-width="auto" style="max-width: 600px">
      <el-form-item label="头像">
        <div>
            <img :src="editForm.avatar" alt="" width="100px" height="100px">
        </div>
        <el-upload
            class="upload-demo"
            name="file"
            action="http://localhost:3000/upload/img"
            :headers="uploadHeader"
            :show-file-list="false"
            :on-success="handleSuccess"
            >
            <el-button type="primary">上传</el-button>
        </el-upload>
      </el-form-item>
      <el-form-item label="性别">
        <el-radio-group v-model="editForm.sex">
            <el-radio :value="0" size="small">女</el-radio>
            <el-radio :value="1" size="small">男</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="简介">
        <el-input v-model.trim="editForm.desc" />
      </el-form-item>
      <el-form-item label="电话">
        <el-input v-model.trim="editForm.phone" />
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model.trim="editForm.email" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="editData">修改</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<style scoped></style>
